package com.moli.iov.handle.alarm.biz.valid.disarmalarm;

import com.moli.iov.handle.alarm.biz.valid.ValidHandler;
import com.moli.iov.handle.alarm.biz.utils.AlarmUtils;
import com.moli.iov.handle.alarm.model.dto.DisarmAlarmDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * <p>
 *  取消报警 有效性校验
 *
 *      初始化报警防抖数量、判断是否存在报警
 * </p>
 *
 * @author: zql
 * @Date: 2019/2/22 10:55
 */
@Slf4j
@Component
public class DisarmAlarmValidHandler implements ValidHandler<DisarmAlarmDto> {

    @Autowired
    private DisarmAlarmAntiShakeHandler disarmAlarmAntiShakeHandler;

    @Autowired
    private AlarmUtils alarmUtils;

    @Override
    public boolean doHandle(DisarmAlarmDto disarmAlarmDto) {

        if(disarmAlarmDto.getIsAntiShake()){

            alarmUtils.initAlarmOnTimes(disarmAlarmDto.getVin(),
                    disarmAlarmDto.getAlarmCode());
        }

        if(!alarmUtils.isAlarming(disarmAlarmDto.getVin(),
                disarmAlarmDto.getAlarmCode())){
            return false;
        }

        return disarmAlarmAntiShakeHandler.doHandle(disarmAlarmDto);
    }
}
